package cn.tedu.egnotice0905.controller;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import cn.tedu.egnotice0905.base.response.JsonResult;
import cn.tedu.egnotice0905.mapper.NoticeMapper;
import cn.tedu.egnotice0905.pojo.dto.NoticeAddParam;
import cn.tedu.egnotice0905.pojo.dto.NoticeAddQuery;
import cn.tedu.egnotice0905.pojo.entity.Notice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("v1/notice/")
@Slf4j
public class NoticeController {
    @Autowired
    NoticeMapper noticeMapper;
    @PostMapping("add")
    public JsonResult add(@RequestBody NoticeAddParam noticeAddParam) {
        log.debug("添加咨询：{}", noticeAddParam);
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam, notice);
        notice.setUserId(1L);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        notice.setStatus(1);
        noticeMapper.add(notice);
        return JsonResult.ok();

    }
    @GetMapping("list")
    public JsonResult list(NoticeAddQuery noticeAddQuery) {
        log.debug("查询咨询：{}", noticeAddQuery);
        return JsonResult.ok(noticeMapper.list(noticeAddQuery));
    }
    @GetMapping("detail")
    public JsonResult detail(Long id) {
        log.debug("查询咨询详情：{}", id);
        return JsonResult.ok(noticeMapper.detail(id));
    }

}
